package com.xjm.bean.postprocessor;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.annotation.Configuration;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

/**
 * @author jaymin
 * 2021/1/7 23:51
 */
@Configuration
public class MyBeanPostProcessor implements BeanPostProcessor {

	@Override
	@Nullable
	public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
		System.out.println(beanName + " invoking MyBeanPostProcessor#postProcessBeforeInitialization");
		return bean;
	}

	/**
	 * 可以对所有的Bean做统一操作
	 * @param bean the new bean instance
	 * @param beanName the name of the bean
	 * @return
	 * @throws BeansException
	 */
	@Override
	@Nullable
	public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
		System.out.println(beanName + " invoking MyBeanPostProcessor#postProcessAfterInitialization");
		return bean;
	}

}
